package com.ethink.platform.controller.warehouse;

import com.ethink.warehouse.api.request.WarehouseStatusSetRequest;
import com.ethink.warehouse.api.response.WarehouseAddResponse;
import com.ethink.warehouse.api.response.WarehouseDetailsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.warehouse.api.WarehouseFacade;
import com.ethink.warehouse.api.info.WarehouseInfo;
import com.ethink.warehouse.api.request.WarehouseAddRequest;
import com.ethink.warehouse.api.request.WarehouseQueryRequest;
import com.ethink.warehouse.api.request.WarehouseUpdateRequest;

/**
 * 仓库主仓 Controller
 *
 * @author default
 * @date 2022-11-01
 */
@Tag(name = "WarehouseController", description = "仓库主仓 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/warehouse-service")
public class WarehouseController extends BaseController {

    @Autowired
    private WarehouseFacade warehouseFacade;

    @Operation(summary = "分页查询")
    @GetMapping("/warehouse/query")
    public CommonResponse<List<WarehouseInfo>> queryWarehouse(WarehouseQueryRequest request) {
        return succeedWithPage(warehouseFacade.queryWarehouse(request));
    }

    @Operation(summary = "详情查询")
    @GetMapping("/warehouse/get/{warehouseId}")
    public CommonResponse<WarehouseDetailsResponse> getWarehouseById(@PathVariable("warehouseId") Long warehouseId) {
        return succeedWith(warehouseFacade.getWarehouseById(warehouseId));
    }

    @Operation(summary = "查询所有")
    @GetMapping("/warehouse/list")
    public CommonResponse<List<WarehouseInfo>> listWarehouse() {
        return succeedWith(warehouseFacade.listWarehouse());
    }

    @Operation(summary = "新增")
    @PostMapping("/warehouse/add")
    public CommonResponse<WarehouseAddResponse> addWarehouse(@Validated @RequestBody WarehouseAddRequest request) {
        return succeedWith(warehouseFacade.addWarehouse(request));
    }

    @Operation(summary = "更新")
    @PutMapping("/warehouse/update")
    public CommonResponse updateWarehouse(@Validated @RequestBody WarehouseUpdateRequest request) {
        warehouseFacade.updateWarehouse(request);
        return succeed();
    }

    @Operation(summary = "修改状态")
    @PutMapping("/warehouse/setStatus")
    public CommonResponse setWarehouseStatus(@Validated @RequestBody WarehouseStatusSetRequest request) {
        warehouseFacade.setWarehouseStatus(request);
        return succeed();
    }

}